*******************************************************************************
*** Description: 	This document provides code for reproducing the 		***
***					figures in Study 1 of the paper, "Elections Increase 	***
***					Satisfaction with Democracy," which is authored by 		***
***					Shane P. Singh and appears in Comparative Political		***
***					Studies. It also provides code for reproducing			***
***					statistics associated with claims made in the text.		***
*******************************************************************************


**************
**************
*Set the Version                                                                                                                                 
**************
**************
version 17



**************
**************
*Install Required Packages                                                                                                                 
**************
**************
ssc install coefplot
ssc install yalescheme



**************
**************
*Open the Study 1 Dataset
**************
**************
use "Study 1.dta", clear



**************
**************
*Evidence for Claim Made in the Text: 
*The countries and years in my sample in which intervening elections were held are: Croatia
*(2011); Greece (1989, 2004, and 2009); Ireland (2007); Italy (1992); the Netherlands (2006 and
*2012); Portugal (2005, 2015, and 2019); Spain (1989 and 2004); and Sweden (2014 and 2018).
**************
**************	
tab country_and_year if interrupt_nat == 1 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer" & age_harmonized ~=. & female_harmonized ~=. &  educ_harmonized_0_10 ~=. &  income_harmonized_0_10 ~=. & swd_same_direction_0_10 ~=.


**************
**************
*Evidence for Claim Made in the Text: 
*Ultimately, my analysis data include nearly 17,000 people across these 15 interrupted surveys and eight countries,
*with 53 percent of respondents interviewed before election day and 47 percent interviewed on election day or afterward.
**************
**************	
tab country_and_year interv_on_or_after_elec if interrupt_nat == 1 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer"  & age_harmonized ~=. & female_harmonized ~=. &  educ_harmonized_0_10 ~=. &  income_harmonized_0_10 ~=. & swd_same_direction_0_10 ~=., row




**************
**************
*Figure 1
**************
**************
preserve

keep if  interrupt_nat == 1 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer"  & age_harmonized ~=. & female_harmonized ~=. &  educ_harmonized_0_10 ~=. &  income_harmonized_0_10 ~=. & swd_same_direction_0_10 ~=.

graph set window fontface "LMRoman10-Regular" 

lpoly swd_same_direction_0_10   time_from_elec if time_from_elec>=0  & interrupt_nat == 1, nograph gen(above_x above_s) se(above_se) kernel(triangle) bw(75) n(900)
gen lb0 = above_s - 1.96*above_se
gen ub0 = above_s + 1.96*above_se

lpoly swd_same_direction_0_10   time_from_elec if time_from_elec<0 & interrupt_nat == 1, nograph gen(below_x below_s) se(below_se) kernel(triangle) bw(75) n(900)
gen lb1 = below_s - 1.96*below_se
gen ub1 = below_s + 1.96*below_se




twoway ///
	line above_s above_x  if above_x<=349 , lcolor(red) lwidth(medthick) lpattern(solid) || ///
	line below_s below_x if below_x>=-350 , lcolor(black) lwidth(medthick) lpattern(longdash) ||	///
	rarea ub0 lb0 above_x  if above_x<=349 , fcolor(red*.5%50) lwidth(none)  || ///
	rarea ub1 lb1 below_x  if below_x>=-350 , fcolor(black*.5%50) lwidth(none)  || ///
	pci 4 0  6 0, lcolor(navy) lwidth(thick) lpattern(solid)  || ///
	, xtitle("Days From National Election", size(medium) margin(top))	///  
		xline(0,  lcolor(navy) lwidth(thick) lpattern(solid)) 		///
		ytitle("Predicted Satisfaction" "with Democracy", size(medium))    ///   
		legend(off) title("") graphregion(color(white)) ///
		scheme(yale) xsize(7)  ysize(6) ylabel(0(2)10) yscale(range(0 10))	/// 
		xlabel(-350 (175) 350, labsize(small)) ylabel(, labsize(small))

drop above_x-ub1	


bysort interv_on_or_after_elec: sum time_from_elec //*From note to figure: "The number of observations is 16,671, with 8,882 recorded before election day and 7,789 on or after election day.

restore 



**************
**************
*Figure 2
**************
**************
xtreg swd_same_direction_0_10 i.interv_on_or_after_elec##c.time_from_elec  age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10 if interrupt_nat == 1 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer", i(svy_and_wv_and_cntry_year_num) fe
margins, dydx(interv_on_or_after_elec) at(time_from_elec=0) post coeflegend level(95)
est store main_model


gen interv_on_or_after_no_elec = interv_on_or_after_elec //generate copy of binary interview date variable for graphing purposes
xtreg swd_same_direction_0_10 i.interv_on_or_after_no_elec##c.time_from_elec  age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10 if interrupt_nat == 0 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer", i(svy_and_wv_and_cntry_year_num) fe
margins, dydx(interv_on_or_after_no_elec) at(time_from_elec=0) post coeflegend level(95)
est store no_election


gen interv_on_or_after_elec_Foa = interv_on_or_after_elec //generate copy of binary interview date variable for graphing purposes
xtreg swd_same_direction_Foa_dich_0_10 i.interv_on_or_after_elec_Foa##c.time_from_elec  age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10 if interrupt_nat == 1 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer", i(svy_and_wv_and_cntry_year_num) fe
margins, dydx(interv_on_or_after_elec_Foa) at(time_from_elec=0) post coeflegend level(95)
est store Foa


gen interv_on_or_after_elec_evs_wvs = interv_on_or_after_elec //generate copy of binary interview date variable for graphing purposes
xtreg swd_same_direction_0_10 i.interv_on_or_after_elec_evs_wvs##c.time_from_elec  age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10 if interrupt_nat == 1 & source ~= "AmericasBarometer" & source ~= "Latinobarometer" , i(svy_and_wv_and_cntry_year_num) fe
margins, dydx(interv_on_or_after_elec_evs_wvs) at(time_from_elec=0) post coeflegend level(95)
est store evs_wvs


gen interv_on_or_after_elec_contacts = interv_on_or_after_elec //generate copy of binary interview date variable for graphing purposes
xtreg swd_same_direction_0_10 i.interv_on_or_after_elec_contacts##c.time_from_elec  age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10 contacts  if interrupt_nat == 1  & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer"  , i(svy_and_wv_and_cntry_year_num) fe
margins, dydx(interv_on_or_after_elec_contacts) at(time_from_elec=0) post coeflegend level(95)
est store contacts


graph set window fontface "LMRoman10-Regular" 

coefplot ///
		(main_model, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
		(no_election, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
		(Foa, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
		(evs_wvs, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
		(contacts, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
	,  scheme(yale) horizontal 	///
	coeflabels( 1.interv_on_or_after_elec  	= 						`" "Main" "Model"  "'  ///
				1.interv_on_or_after_no_elec  	= 				`" "Countries with" "no Election"  "'  ///
				1.interv_on_or_after_elec_Foa  	= 					`" "Foa et al." "SWD Measure"  "'  ///
				1.interv_on_or_after_elec_evs_wvs  	= 					`" "EVS/WVS" "Included"  "'  ///
				1.interv_on_or_after_elec_contacts  	= 				`" "Control for" "Contacts"  "'  ///
				) ///
	legend(off) ///
	graphregion(margin(small)) /// 
	xlabel(-1(0.5)1, labsize(vsmall)) xscale(range(-1.1 1.1)) xtitle("Estimated Ef`=uchar(14)'fect of Elections on" "Satisfaction with Democracy", size(small) margin(top)) ///
	ylabel(, labsize(vsmall))  ///
	xline(0,   lcolor(gs10) lwidth(thin) lpattern(solid)) ///
	level(95) format(%9.1f) ysize(4.5) xsize(5.5) scale(1.35) ///
	graphregion(color(white) lcolor(black) lwidth(thick) margin(medsmall))
		
	

	

**************
**************
*Evidence for Claim Made in the Text: 
*Results, shown at the top of Figure 2, verify a precisely estimated upward
*impact of elections on SWD (about 0.23 units, with a two-sided p-value < 0.001). 	
**************
**************	
xtreg swd_same_direction_0_10 i.interv_on_or_after_elec##c.time_from_elec  age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10 if interrupt_nat == 1 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer", i(svy_and_wv_and_cntry_year_num) fe
margins, dydx(interv_on_or_after_elec) at(time_from_elec=0) level(95)

	
	
**************
**************
*Evidence for Claim Made in the Text: 
*The estimated impact of elections in one country on SWD in others is negative...	
**************
**************		
xtreg swd_same_direction_0_10 i.interv_on_or_after_no_elec##c.time_from_elec  age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10 if interrupt_nat == 0 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer", i(svy_and_wv_and_cntry_year_num) fe
margins, dydx(interv_on_or_after_no_elec) at(time_from_elec=0) level(95)	
	
	
**************
**************
*Evidence for Claim Made in the Text: 
*The binary Foa et al. (2020) measure, which classifies respondents as satisfied or not,
*helps illustrate this. When it is used as the dependent variable, the estimated impact of elections
*on the probability of being satisfied with democracy is just under 0.04. 	
**************		
**************
xtreg swd_same_direction_Foa_dich i.interv_on_or_after_elec##c.time_from_elec  age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10 if interrupt_nat == 1 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer", i(svy_and_wv_and_cntry_year_num) fe
margins, dydx(interv_on_or_after_elec) at(time_from_elec=0) level(95)



**************
**************
*Evidence for Claim Made in the Text: 
*In a linear regression of SWD on the number of contacts, the covariates, and survey-level fixed effects, the
*coefficient on the number of contacts is 0.006, and its two-sided p-value is 0.306.	
**************		
**************
xtreg swd_same_direction_0_10  age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10 contacts  if interrupt_nat == 1  & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer", i(svy_and_wv_and_cntry_year_num) fe




**************
**************
*Figure 3
**************
**************
gen interv_on_or_after_elec_happy = interv_on_or_after_elec //generate copy of binary interview date variable for graphing purposes
xtreg happy i.interv_on_or_after_elec_happy##c.time_from_elec age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10  if interrupt_nat == 1 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer", i(svy_and_wv_and_cntry_year_num) fe 
margins, dydx(interv_on_or_after_elec_happy) at(time_from_elec=0) post coeflegend level(95)
est store happy

gen interv_on_or_after_elec_ppltrst = interv_on_or_after_elec //generate copy of binary interview date variable for graphing purposes
xtreg ppltrst i.interv_on_or_after_elec_ppltrst##c.time_from_elec age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10  if interrupt_nat == 1 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer", i(svy_and_wv_and_cntry_year_num) fe 
margins, dydx(interv_on_or_after_elec_ppltrst) at(time_from_elec=0) post coeflegend level(95)
est store ppltrst

gen interv_on_or_after_elec_trstprt = interv_on_or_after_elec //generate copy of binary interview date variable for graphing purposes
xtreg trstprt i.interv_on_or_after_elec_trstprt##c.time_from_elec age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10  if interrupt_nat == 1 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer", i(svy_and_wv_and_cntry_year_num) fe 
margins, dydx(interv_on_or_after_elec_trstprt) at(time_from_elec=0) post coeflegend level(95)
est store trstprt

gen interv_on_or_after_elec_trstplt = interv_on_or_after_elec //generate copy of binary interview date variable for graphing purposes
xtreg trstplt i.interv_on_or_after_elec_trstplt##c.time_from_elec age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10  if interrupt_nat == 1 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer", i(svy_and_wv_and_cntry_year_num) fe 
margins, dydx(interv_on_or_after_elec_trstplt) at(time_from_elec=0) post coeflegend level(95)
est store trstplt

gen interv_on_or_after_elec_stfeco = interv_on_or_after_elec //generate copy of binary interview date variable for graphing purposes
xtreg stfeco i.interv_on_or_after_elec_stfeco##c.time_from_elec age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10  if interrupt_nat == 1 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer", i(svy_and_wv_and_cntry_year_num) fe 
margins, dydx(interv_on_or_after_elec_stfeco) at(time_from_elec=0) post coeflegend level(95)
est store stfeco

gen interv_on_or_after_elec_stfgov = interv_on_or_after_elec //generate copy of binary interview date variable for graphing purposes
xtreg stfgov i.interv_on_or_after_elec_stfgov##c.time_from_elec age_harmonized female_harmonized educ_harmonized_0_10 income_harmonized_0_10  if interrupt_nat == 1 & source ~= "WVS_EVS" & source ~= "AmericasBarometer" & source ~= "Latinobarometer", i(svy_and_wv_and_cntry_year_num) fe 
margins, dydx(interv_on_or_after_elec_stfgov) at(time_from_elec=0) post coeflegend level(95)
est store stfgov


graph set window fontface "LMRoman10-Regular" 

coefplot ///
		(happy, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
		(ppltrst, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
		(trstprt, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
		(trstplt, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
		(stfeco, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
		(stfgov, offset(0) recast(scatter) mcolor(black) msize(medium) ciopts(lpattern(solid) lcolor(black))) ///
	,  scheme(yale) horizontal 	///
	coeflabels( 1.interv_on_or_after_elec_happy  	= 						`" "Expressed" "Happiness"  "'  ///
				1.interv_on_or_after_elec_ppltrst  	= 					`" "Interpersonal" "Trust"  "'  ///
				1.interv_on_or_after_elec_trstprt  	= 					`" "Trust in" "Parties"  "'  ///
				1.interv_on_or_after_elec_trstplt  	= 					`" "Trust in" "Politicians"  "'  ///
				1.interv_on_or_after_elec_stfeco  	= 						`" "Satisfaction with" "Economy"  "'  ///
				1.interv_on_or_after_elec_stfgov  	= 						`" "Satisfaction with" "Government"  "'  ///
				) ///
	legend(off) ///
	graphregion(margin(small)) /// 
	xlabel(-1(0.5)1, labsize(vsmall)) xscale(range(-1.1 1.1)) xtitle("Estimated Ef`=uchar(14)'fect of Elections on" "Dependent Variable", size(small) margin(top)) ///
	ylabel(, labsize(vsmall))  ///
	xline(0,   lcolor(gs10) lwidth(thin) lpattern(solid)) ///
	level(95) format(%9.1f) ysize(5) xsize(5.5) scale(1.35) ///
	graphregion(color(white) lcolor(black) lwidth(thick) margin(medsmall)) 



	




*   /\                 /\
*  / \'._   (\_/)   _.'/ \
* /_.''._'--('.')--'_.''._\* Thanks for replicating!
* | \_ / `;=/ " \=;` \ _/ |
*  \/ `\__|`\___/`|__/`  \/
*   `      \(/|\)/       
